package service;

import dao.DoctorDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.Doctor;
import pojo.DoctorPage;

import java.util.List;

/**
 * @author 李主席
 * @create 2020-12-11 9:04
 */
@Service
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    private DoctorDao doctorDao;

    @Override
    public DoctorPage getAllDoctors(Integer page, Integer size) {
        Integer start = (page - 1) * size;
        List<Doctor> doctors = doctorDao.selectAllDoctors(start, size);
        Integer count = doctorDao.selectDoctorsCount();
        Integer pageCount = count % size == 0 ? count / size : count / size + 1;
        DoctorPage doctorPage = new DoctorPage();
        doctorPage.setRowCount(count);
        doctorPage.setPageNum(page);
        doctorPage.setPageCount(pageCount);
        doctorPage.setPageSize(size);
        doctorPage.setDockerList(doctors);

        return doctorPage;
    }

    @Override
    public Integer addOneDoctor(Doctor doctor) {
        return doctorDao.insertOneDoctor(doctor);
    }

    @Override
    public Integer setOneDoctor(Doctor doctor) {
        return doctorDao.updateOneDoctor(doctor);
    }

    @Override
    public Doctor getDoctorById(Integer id) {
        return doctorDao.selectDoctorById(id);
    }

    @Override
    public Integer delAllDoctors(Integer id) {
        return doctorDao.deleteAllDoctors(id);
    }
}
